@echo off
echo Searching for member ID with email='x@yz.ru'...
"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE" -S BELLMAN\SQLEXPRESS -E -d smart-dating -t 5000 -h -1 -Q"select usr_id from membership where email='x@yz.ru'" > member_id_res.txt

for /f "delims=" %%a in ('head 1 member_id_res.txt') do set MEMBER_ID=%%a
echo Found member ID: %MEMBER_ID%.

echo Deleting all location data for member %MEMBER_ID%.
"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE" -S BELLMAN\SQLEXPRESS -E -d smart-dating -t 5000 -Q"delete from location where usr_id='%MEMBER_ID%'"

echo Deleting all messages from or to member %MEMBER_ID%.
"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE" -S BELLMAN\SQLEXPRESS -E -d smart-dating -t 5000 -Q"delete from msgs where usr_from='%MEMBER_ID%' or usr_to='%MEMBER_ID%'"

echo Deleting all personal data for member %MEMBER_ID%.
"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE" -S BELLMAN\SQLEXPRESS -E -d smart-dating -t 5000 -Q"delete from personaldata where usr_id='%MEMBER_ID%'"

echo Deleting all membership data for member %MEMBER_ID%.
"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE" -S BELLMAN\SQLEXPRESS -E -d smart-dating -t 5000 -Q"delete from membership where usr_id='%MEMBER_ID%'"